package gov.nist.ssd.swqb.core.search;

import static gov.nist.ssd.swqb.util.Static.concat;

import com.hp.hpl.jena.rdf.model.Model;

class LitteralRegexSearch extends AbstractSelectSearch {

  public LitteralRegexSearch(RegexMatchText searchText, Model model, int requestsSize) {
    super(searchText,
          model,
          requestsSize,
          varName("x"),
          searchPattern(
            concat(
              "PREFIX pf: <http://jena.hpl.hp.com/ARQ/property#>",
              "SELECT DISTINCT ?x",
              "WHERE {",
              "  { ?x ?a ?b . }",
              "  UNION",
              "  { ?a ?b ?x .}",
              "  FILTER (isLiteral(?x) && regex(str(?x), \"%1$s\"))",
              "}"
            )
          )
        );
  }
}
